import { EditType } from "@/type/BaseEnum"
import { ref } from "vue"
import useInstance from "@/hooks/useInstance";
import {deleteApi} from "@/api/menu";
import {message} from "ant-design-vue";

export default function useMenu(refresh:any) {
    const { global } = useInstance()
    //弹框ref属性
    const addRef = ref()
    //新增
    const addBtn = () => {
        addRef.value.show(EditType.ADD)
    }
    //编辑
    const editBtn = (row:any) => {
        addRef.value.show(EditType.EDIT,row)
    }
    //删除
    const deleteBtn =async (row:any) => {
            //信息确认
        const confirm = await global.$myConfirm();
        if (confirm) {
            let res = await deleteApi(row.menuId)
            if(res && res.code == 200){
                message.success(res.msg)
                //刷新列表
                refresh()
            }
        }
    }
    return {
        addBtn,
        editBtn,
        deleteBtn,
        addRef
    }
}
